#include <iostream>
using namespace std;
int nums[3] = {1, 2, 3};

int count = 0;
void print(int n, int m){
    for(int i = 0; i < (1 << n); i++){
        int t = i;
        int cnt = 0;    //记录1的个数
        while(t){
            cnt++;
            t = t & (t - 1);//消除低位的1
        }
        if(cnt == m){   //m个数符合要求
            count++;
            //输出
            for(int j = 0; j < n; j++){
                if(i & (1 << j)){
                    cout<<nums[j]<<" "; //输入该位代表的数
                }
            }
            cout<<endl;
        }
    }
}

int main(){
    int n = 3, m = 2;
    print(n, m);
    cout<<"n个数中任意m个数的组合个数:"<<count<<endl;//cnm
    return 0;
}
